import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		screens: [],
		sessionInfo: {},
		sessionSeatList: [],
		seatsCode: [],
		userPhone: '',
		userInfo: {
			birthday: "",
			gender: "",
			name: '',
			nickName: "",
			phoneNo: "",

		},
		filmInfo: {},
		cinemaConfig: {},
		cardPolicy: {},
		cinemaName: '',
		cinemaPhone: '',
		cinemaAddress: '',
		goodsList: []
	},
	mutations: {
		addGoodsList(state, goods) {
			const index = state.goodsList.findIndex(item => item.goodsCode == goods.goodsCode)
			if (index == -1) {
				state.goodsList.push(goods)
			} else {
				state.goodsList[index] = goods;
			}
		},
		subtractGoodsList(state, goods) {
			const index = state.goodsList.findIndex(item => item.goodsCode == goods.goodsCode)
			state.goodsList[index] = goods;
			if (state.goodsList[index].count == 0) {
				state.goodsList.splice(index, 1)
			}
		},
		clearCart(state) {
			state.goodsList = []
		},
		setCinemaName(state, name) {
			state.cinemaName = name
		},
		setCinemaAddress(state, address) {
			state.cinemaAddress = address
		},
		setCinemaPhone(state, phone) {
			state.cinemaPhone = phone
		},
		setScreens(state, screens) {
			state.screens = screens
		},
		setSessionStore(state, info) {
			state.sessionInfo = info
		},
		setSessionSeatList(state, list) {
			state.sessionSeatList = list
		},
		setSeatsCode(state, list) {
			state.seatsCode = list
		},
		setPhone(state, phone) {
			state.userPhone = phone
		},
		setUserInfo(state, info) {
			state.userInfo = info
		},
		setFilmInfo(state, info) {
			state.filmInfo = info
		},
		setCinemaConfig(state, config) {
			state.cinemaConfig = config
		},
		setCardPolicy(state, policy) {
			tate.cardPolicy = config
		}
	}
})
export default store